/*
 *   Clovis
 *   Copyright (C) 2008 SFWOL
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef __NODE_H
#define __NODE_H

#include "ClovisVariable.h"
#include "CString.h"

#include <list>
#include <vector>

namespace clovis {

	namespace core {

       enum NODE_ADD_METHOD {

			//! Copy method do not replace existing node , copy double
        	ADD,
        	//! Copy method replace existing node and copy others
        	REPLACE

        };

		class Node{

            public:

                    /*!
                     * enpty constructor
                     */
                    Node();

                    /*!
                     * Constructor
                     * \arg value The node's value
                     */
                    Node(ClovisVariable * value);

                    /*!
                     * Destructor
                     * Vide la mémoire
                     */
                    ~Node();

                    /*!
                     * getValue
                     * \return Node's value
                     */
                    ClovisVariable * getValue();

                    /*!
                     * setValue
                     * \arg New Node's value
                     */
                    void setValue(ClovisVariable * value);

                    /*!
                     * addNode
                     * Ajoute un noeud a la liste
                     * \arg la valeur du nouveau fils
                     */
                    Node * addNode(ClovisVariable * value , NODE_ADD_METHOD methode = REPLACE);

                    /*!
                     * getNode
                     * Retourne le noeud selon sa valeur
                     */
                    Node * getNode(ClovisVariable * value);

                    /*!
                     * getNode
                     * retourne le noeud issu du chemin passé en paramètre
                     * \arg path Le chemin a traverser
                     */
                    Node * getNode(CString path);

                    /*!
                     * getNodes
                     * Retourne la liste des noeuds ayant comme nom x
                     * \arg liste la liste a manipuler
                     * \arg value Nom des objets a chercher
                     * \arg node La ou débute la recherche
                     * \arg profondeur de la recherche maximale
                     * \return la liste resultant du traitement
                     */
                    std::list<Node*> getNodes(std::list<Node*> liste , CString name , Node * node , CInteger limit);

                    /*!
                     * print
                     */
                    void print(CString path="");

                    /*!
                     * addTree
                     * Add a tree to this node
                     * \arg tree Tree to copy
                     * \arg method Copy method
                     */
                    void addTree(Node * tree , NODE_ADD_METHOD method = REPLACE);

                    /*!
                     * getSons
                     * \return List of node son's of current node
                     */
                    std::list<Node*> getSons();

            private:

                    Node * getPath(CString path , Node * node);

                    ClovisVariable * value;
                    std::list<Node*> sons;

		};

	};

};

#endif

